function Logic() {

    this.person;
    this.possibleBuildings = Array();
    this.upcomingBuildings = Array(new Object, new Object, new Object);
    this.difficulty = .5;

    this.init = function () {

        this.person = this.makeNewPerson();

        this.initializeBuildings();

        game.manager.lastBuildingDrawnDay = 15;

        this.upcomingBuildings[0].locTag = "parents";
        this.upcomingBuildings[0].hitdate = 6;
        this.upcomingBuildings[0].opportunities = game.opportunities.getOpportunities('parents');
        game.draw.building(this.upcomingBuildings[0].locTag, this.upcomingBuildings[0].hitdate)

        this.upcomingBuildings[1].locTag = "bank";
        this.upcomingBuildings[1].hitdate = 11;
        this.upcomingBuildings[1].opportunities = game.opportunities.getOpportunities('bank');
        game.draw.building(this.upcomingBuildings[1].locTag, this.upcomingBuildings[1].hitdate)

        this.upcomingBuildings[2].locTag = "university";
        this.upcomingBuildings[2].hitdate = 16;
        this.upcomingBuildings[2].opportunities = game.opportunities.getOpportunities('university');
        game.draw.building(this.upcomingBuildings[2].locTag, this.upcomingBuildings[2].hitdate)

        this.person.traits.push(game.traits.getBackground());
        this.person.traits.push(game.traits.getLifestyle());
        this.person.traits.push(game.traits.getLifestyle());
        this.person.traits.push(game.traits.getLifestyle());

        for (trait in this.person.traits) {
            this.person.traits[trait].execute();
        }
        var tuitionCost = function () {
            game.logic.person.money += (-1) * (8000 + Math.round(4000 * game.difficulty));

            if (game.traits.checkTrait('Alcoholic') || game.traits.checkTrait('Pot Head')) {
                if(game.logic.person.GPA == 4.0){
                    game.logic.person.GPA += ((game.logic.person.timesStudied) - (game.logic.person.timesPartied * 2 + (game.difficulty * 10))) / 10;    
                }                    
            }
            else{
                if(game.logic.person.GPA == 4.0){
                    game.logic.person.GPA += ((game.logic.person.timesStudied) - (game.logic.person.timesPartied + (game.difficulty * 10))) / 10;    
                } 
            }

        };
        game.manager.addToInventory(
			'Tuition Payment',
			tuitionCost,
			120,
			0,
			'Books, Professors, Research, Football Stadium Improvments are not cheap. You must pay your tuition of $8000.',
			true
	   );
    } 

    this.resetLogic = function() {

    }


    this.newTurn = function() {
        this.updateBuildings();
        console.log(this.upcomingBuildings[0]);
    }



    // Helpers

    this.updateBuildings = function() {
        this.upcomingBuildings[0] = this.upcomingBuildings[1];
        this.upcomingBuildings[1] = this.upcomingBuildings[2];
        var loc = this.possibleBuildings[Math.floor(Math.random() * this.possibleBuildings.length)].locTag;
        this.upcomingBuildings[2] = {
            hitdate: this.upcomingBuildings[1].hitdate + Math.round(Math.random()*4)+5,
            locTag: loc,
            opportunities: game.opportunities.getOpportunities(loc)
        }
        game.draw.building(this.upcomingBuildings[2].locTag, this.upcomingBuildings[2].hitdate);
    }

    this.getEventByName = function(eventName) {
        for (var i = 0; i < this.allEventList.length; i++) {
            if (this.allEventList[i].name === this.eventName) {
                return this.allEventList[i];
            }
        }
        return null;
    }


    this.initializeBuildings = function() {
        this.possibleBuildings.push(this.makeNewBuilding("bank", 30));
        this.possibleBuildings.push(this.makeNewBuilding("bar", 30));
        this.possibleBuildings.push(this.makeNewBuilding("university", 30));
        this.possibleBuildings.push(this.makeNewBuilding("mall", 30));
        // this.possibleBuildings.push(this.makeNewBuilding("CourtHouse", 30));
        // this.possibleBuildings.push(this.makeNewBuilding("Home", 30));
        //this.possibleBuildings.push(this.makeNewBuilding("Parents", 30));
        // this.possibleBuildings.push(this.makeNewBuilding("Gym", 30));
    }


    // Objects

    this.makeNewPerson = function () {
        var Person = new Object();
        Person.gender = (Math.random() > .5) ? "M" : "F";
        Person.name = "Mr. Money";

        Person.happiness = 60;
        Person.GPA = 4.0;
        Person.money = 1000;

        Person.timesStudied = 10;
        Person.timesPartied = 10;

        Person.traits = new Array();

        Person.creditHours = 0; //Assuming 15 per semester
        Person.score = 0
        Person.outstandingDebt = 0;
        Person.incomeBiWeekly = 0;
        Person.costsBiWeekly = 0;
        Person.hasVehicle = false;
        Person.hasSignificantOther = false;
        Person.housing = "";
        return Person;
    }

    this.makeNewBuilding = function(locationTag, probability) {
        var Location = new Object();
        Location.locTag = locationTag;
        Location.probability = probability;
        Location.lastTurnHappened = -1;
        return Location;
    }

}




